package acwing.模拟;



import java.util.Scanner;

/**
 * 连号区间数
 *
 * @author yang
 * @date 2021/11/25
 */
public class 连号区间数 {

    static int N = 50010;
    static int[] arr = new int[N];

    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int n =  s.nextInt();
        for (int i = 0; i < n; i++) arr[i] = s.nextInt();

        int res = 0;
        for (int i = 0; i < n; i++) { // 枚举左端点
            int max = Integer.MIN_VALUE, min = Integer.MAX_VALUE;
            for (int j = i; j < n; j++) { // 枚举右端点
                max = Math.max(max, arr[j]);
                min = Math.min(min,arr[j]);
                // 连号区间 max - min == 右端点 - 左端点
                if (max - min == j - i) res++;
            }
        }
        System.out.println(res);
    }
}
